﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FooFun.DataElements.Dtos;
using System.Web;

namespace FAQFrameworks
{
    public class ThemeConfig
    {
        //todo 更高效的使用主题
        public static string Theme
        {
            get
            {
                Guid forumId = FAQContext.Current.ForumId;

                string key = GetKey(forumId);
                string theme
                    = HttpContext.Current.Application[key] as string;
                if (theme == null)
                {
                    theme = UserTheme;

                    if (string.IsNullOrEmpty(theme))
                    {
                        theme = ThemeConfig.ForumTheme;

                        if (string.IsNullOrEmpty(theme))
                        {
                            theme = DefaultTheme;
                        }
                    }

                    HttpContext.Current.Application[key] = theme;
                }

                return theme;
            }
        }

        public static string DefaultTheme
        {
            get
            {
                return ConfigManager.DefaultTheme;
            }
        }

        private static string GetKey(Guid forumId)
        {
            string key = "ForumId_" + forumId;

            return key;
        }

        public static string ForumTheme
        {
            get
            {
                Guid forumId = FAQContext.Current.ForumId;

                ForumManager forumManager = new ForumManager();
                IDataElement de = forumManager.GetElement(forumId);

                string theme = de["Theme"].Value as string;

                return theme;
            }
        }

        public static string UserTheme
        {
            get
            {
                return null;
            }
        }
    }
}
